define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'byd_designer/index' + location.search,
                    add_url: 'byd_designer/add',
                    edit_url: 'byd_designer/edit',
                    del_url: 'byd_designer/del',
                    multi_url: 'byd_designer/multi',
                    import_url: 'byd_designer/import',
                    table: 'byd_designer',
                }
            });

            var table = $("#table");
            // let time =setInterval(() => {
            //     $.ajax({
            //         type: 'POST',
            //         url: 'byd_designer/isHaveNewAfter',
            //         success: function (data) {
            //             if (data.code == 1) {
            //                 if (data.data > 0) {
            //                     // 提示音
            //                     // var audio = document.getElementById('reftips');
            //                     // audio.play();
            //                     // 提示框
            //                     Layer.alert('您有新的设计师申请，请尽快审核', {
            //                         skin: 'layui-layer-molv' //样式类名  自定义样式
            //                         , closeBtn: 0    // 是否显示关闭按钮
            //                         , anim: 1 //动画类型
            //                         , btn: ['马上去处理', '我知道了'] //按钮
            //                         , icon: 6    // icon
            //                         , yes: function (index) {
            //                             handleTui('go');
            //
            //                             //audio.pause();
            //                             //audio.currentTime = 0;
            //                             layer.close(index);
            //                         }, btn2: function (index) {
            //                             handleTui('know');
            //                             //audio.pause();
            //                             //audio.currentTime = 0;
            //
            //                             layer.close(index);
            //                         }
            //                     });
            //                 }
            //             }
            //         }
            //     });
            // }, 1000*30);
            function handleTui(type) {
                $.ajax({
                    type: 'POST',
                    url: 'byd_designer/handleTui',
                    data: { type: type },
                    async: false,//同步
                    success: function (data) {
                        if (data.code == 1) {
                            if (data.data == 'go') {
                                // 点击菜单 "订单管理"，打开tab页
                                $('.sidebar-menu li a[addtabs=129]').click();
                            }
                        }
                    }
                });
            }
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'byduser.username', title: __('用户名'), operate: 'LIKE'},
                        {field: 'username', title: __('真实姓名'), operate: 'LIKE'},
                        {field: 'sex', title: __('性别'), searchList: {"0":__('男'),"1":__('女')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('申请时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'idcart', title: __('Idcart'), operate: 'LIKE'},
                        {field: 'address', title: __('Address'), operate: 'LIKE'},
                        {field: 'addressxq', title: __('Addressxq'), operate: 'LIKE'},
                        {field: 'email', title: __('Email'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'desimage', title: __('Avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'level', title: __('Level'), searchList: {"3":__('二级设计师会员'),"4":__('三级设计师会员'),"5":__('一级设计师会员')}, formatter: Table.api.formatter.normal},
                        {field: 'state', title: __('State'), searchList: {"0":__('State 0'),"1":__('State 1'),"2":__('State 2')}, formatter: Table.api.formatter.normal},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});